package net.gdface.sdk.decorator;
import java.nio.ByteBuffer;
import net.gdface.sdk.FaceApi;
import net.gdface.thrift.TypeTransformer;
import net.gdface.thrift.exception.ServiceRuntimeException;
import com.facebook.swift.service.ThriftException;
import com.facebook.swift.service.ThriftService;
import com.facebook.swift.service.ThriftMethod;
/**
 * decorator pattern 装饰者模式实现{@link FaceApi}接口<br>
 * 转发所有{@link FaceApi}接口方法到{@link #delegate()}指定的实例,<br>
 * unchecked后缀的方法将所有显式申明的异常封装到{@link RuntimeException}抛出<br>
 * 计算机生成代码(generated by automated tools ThriftServiceDecoratorGenerator @author guyadong)<br>
 * @author guyadong
 *
 */
@ThriftService("FaceApi")
public class FaceApiThriftDecorator {
    private final FaceApi delegate;
    
    public FaceApiThriftDecorator(FaceApi delegate) {
        super();
        if(null == delegate){
            throw new NullPointerException("delegate is null");
        }
        this.delegate = delegate;
    }

    /**
     * 返回被装饰的{@link FaceApi}实例
     * @return
     */
    public FaceApi delegate() {
        return delegate;
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#compare2Face(byte[],net.gdface.sdk.CodeInfo,byte[],net.gdface.sdk.CodeInfo)}
     */
    @ThriftMethod(exception = {
                @ThriftException(type=net.gdface.image.decorator.ImageErrorException.class, id=1),
                @ThriftException(type=NotFaceDetectedException.class, id=2),
                @ThriftException(type=ServiceRuntimeException.class, id=3)
                })
    public double compare2Face(ByteBuffer imgData1,
        CodeInfo facePos1,
        ByteBuffer imgData2,
        CodeInfo facePos2) 
        throws net.gdface.image.decorator.ImageErrorException,NotFaceDetectedException,ServiceRuntimeException{
        try{
            return delegate().compare2Face(TypeTransformer.getInstance().to(
                    imgData1,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    facePos1,
                    CodeInfo.class,
                    net.gdface.sdk.CodeInfo.class),
                TypeTransformer.getInstance().to(
                    imgData2,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    facePos2,
                    CodeInfo.class,
                    net.gdface.sdk.CodeInfo.class));
        }
        catch(net.gdface.image.ImageErrorException e){
            throw new net.gdface.image.decorator.ImageErrorException(e);
        }
        catch(net.gdface.sdk.NotFaceDetectedException e){
            throw new NotFaceDetectedException(e);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#compareCode(byte[],byte[])}
     */
    @ThriftMethod()
    public double compareCode(ByteBuffer code1,
        ByteBuffer code2) 
        throws ServiceRuntimeException{
        try{
            return delegate().compareCode(TypeTransformer.getInstance().to(
                    code1,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    code2,
                    ByteBuffer.class,
                    byte[].class));
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#detectAndCompare2Face(byte[],net.gdface.sdk.FRect,byte[],net.gdface.sdk.FRect)}
     */
    @ThriftMethod(exception = {
                @ThriftException(type=net.gdface.image.decorator.ImageErrorException.class, id=1),
                @ThriftException(type=NotFaceDetectedException.class, id=2),
                @ThriftException(type=ServiceRuntimeException.class, id=3)
                })
    public double detectAndCompare2Face(ByteBuffer imgData1,
        FRect detectRect1,
        ByteBuffer imgData2,
        FRect detectRect2) 
        throws net.gdface.image.decorator.ImageErrorException,NotFaceDetectedException,ServiceRuntimeException{
        try{
            return delegate().detectAndCompare2Face(TypeTransformer.getInstance().to(
                    imgData1,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    detectRect1,
                    FRect.class,
                    net.gdface.sdk.FRect.class),
                TypeTransformer.getInstance().to(
                    imgData2,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    detectRect2,
                    FRect.class,
                    net.gdface.sdk.FRect.class));
        }
        catch(net.gdface.image.ImageErrorException e){
            throw new net.gdface.image.decorator.ImageErrorException(e);
        }
        catch(net.gdface.sdk.NotFaceDetectedException e){
            throw new NotFaceDetectedException(e);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#detectAndGetCodeInfo(byte[],int,net.gdface.sdk.FRect)}
     */
    @ThriftMethod(exception = {
                @ThriftException(type=net.gdface.image.decorator.ImageErrorException.class, id=1),
                @ThriftException(type=NotFaceDetectedException.class, id=2),
                @ThriftException(type=ServiceRuntimeException.class, id=3)
                })
    public java.util.List<CodeInfo> detectAndGetCodeInfo(ByteBuffer imgData,
        int faceNum,
        FRect detectRectangle) 
        throws net.gdface.image.decorator.ImageErrorException,NotFaceDetectedException,ServiceRuntimeException{
        try{
            return TypeTransformer.getInstance().to(
                    delegate().detectAndGetCodeInfo(TypeTransformer.getInstance().to(
                    imgData,
                    ByteBuffer.class,
                    byte[].class),
                faceNum,
                TypeTransformer.getInstance().to(
                    detectRectangle,
                    FRect.class,
                    net.gdface.sdk.FRect.class)),
                    net.gdface.sdk.CodeInfo.class,
                    CodeInfo.class);
        }
        catch(net.gdface.image.ImageErrorException e){
            throw new net.gdface.image.decorator.ImageErrorException(e);
        }
        catch(net.gdface.sdk.NotFaceDetectedException e){
            throw new NotFaceDetectedException(e);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#detectFace(byte[],net.gdface.sdk.FRect)}
     */
    @ThriftMethod(exception = {
                @ThriftException(type=net.gdface.image.decorator.ImageErrorException.class, id=1),
                @ThriftException(type=ServiceRuntimeException.class, id=2)
                })
    public java.util.List<CodeInfo> detectFace(ByteBuffer imgData,
        FRect detectRectangle) 
        throws net.gdface.image.decorator.ImageErrorException,ServiceRuntimeException{
        try{
            return TypeTransformer.getInstance().to(
                    delegate().detectFace(TypeTransformer.getInstance().to(
                    imgData,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    detectRectangle,
                    FRect.class,
                    net.gdface.sdk.FRect.class)),
                    net.gdface.sdk.CodeInfo.class,
                    CodeInfo.class);
        }
        catch(net.gdface.image.ImageErrorException e){
            throw new net.gdface.image.decorator.ImageErrorException(e);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#detectFaceAgain(byte[],net.gdface.sdk.FRect[])}
     */
    @ThriftMethod()
    public java.util.List<CodeInfo> detectFaceAgain(ByteBuffer imgData,
        java.util.List<FRect> detectRects) 
        throws ServiceRuntimeException{
        try{
            return TypeTransformer.getInstance().to(
                    delegate().detectFaceAgain(TypeTransformer.getInstance().to(
                    imgData,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().toArray(
                    detectRects,
                    FRect.class,
                    net.gdface.sdk.FRect.class)),
                    net.gdface.sdk.CodeInfo.class,
                    CodeInfo.class);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#getCodeInfo(byte[],int,net.gdface.sdk.CodeInfo[])}
     */
    @ThriftMethod(exception = {
                @ThriftException(type=NotFaceDetectedException.class, id=1),
                @ThriftException(type=ServiceRuntimeException.class, id=2)
                })
    public java.util.List<CodeInfo> getCodeInfo(ByteBuffer imgData,
        int faceNum,
        java.util.List<CodeInfo> facePos) 
        throws NotFaceDetectedException,ServiceRuntimeException{
        try{
            return TypeTransformer.getInstance().to(
                    delegate().getCodeInfo(TypeTransformer.getInstance().to(
                    imgData,
                    ByteBuffer.class,
                    byte[].class),
                faceNum,
                TypeTransformer.getInstance().toArray(
                    facePos,
                    CodeInfo.class,
                    net.gdface.sdk.CodeInfo.class)),
                    net.gdface.sdk.CodeInfo.class,
                    CodeInfo.class);
        }
        catch(net.gdface.sdk.NotFaceDetectedException e){
            throw new NotFaceDetectedException(e);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#hasFace(byte[],net.gdface.sdk.FRect)}
     */
    @ThriftMethod(exception = {
                @ThriftException(type=net.gdface.image.decorator.ImageErrorException.class, id=1),
                @ThriftException(type=ServiceRuntimeException.class, id=2)
                })
    public boolean hasFace(ByteBuffer imgData,
        FRect detectRectangle) 
        throws net.gdface.image.decorator.ImageErrorException,ServiceRuntimeException{
        try{
            return delegate().hasFace(TypeTransformer.getInstance().to(
                    imgData,
                    ByteBuffer.class,
                    byte[].class),
                TypeTransformer.getInstance().to(
                    detectRectangle,
                    FRect.class,
                    net.gdface.sdk.FRect.class));
        }
        catch(net.gdface.image.ImageErrorException e){
            throw new net.gdface.image.decorator.ImageErrorException(e);
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
    /**
     * @see {@link net.gdface.sdk.FaceApi#isLocal()}
     */
    @ThriftMethod()
    public boolean isLocal() 
        throws ServiceRuntimeException{
        try{
            return delegate().isLocal();
        }
        catch(RuntimeException e){
            throw new ServiceRuntimeException(e);
        }
    }
}